package com.tgu.home_action.dao;

import com.tgu.home_action.pojo.Family;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FamilyMapper {
    /**
     * 通过openid获取用户
     *
     * @param openid：openid
     * @return family
     */
    @Select("select * from family_users where openid=#{openid}")
    Family getByOpenid(String openid);

    /**
     * 插入家属用户
     *
     * @param family：家属用户信息
     */
    void insertFamily(Family family);

    /**
     * 通过id获取家属用户
     *
     * @param id：家属id
     * @return family
     */
    @Select("select * from family_users where id=#{id}")
    Family getById(Integer id);

    /**
     * 更新从微信获取的信息
     *
     * @param family：家属信息
     */
    void updateUserinfo(Family family);

    /**
     * 完善信息
     */
    void updateInformation(Family family);

    /**
     * 获取家属姓名
     */
    @Select("select name from family_users where id=#{id}")
    String getNameById(Integer id);

    /**
     * 修改手机号
     */
    @Update("update family_users set phone=#{phone} where id=#{id}")
    void updatePhone(Family familyUser);

    /**
     * 查询符合条件的家属数量
     */
    int getAccordFamilyNum(Family family);

    /**
     * 志愿者查询家属
     */
    List<Family> adminGetFamily(Family family);

    /**
     * 管理员修改家属信息
     */
    void adminUpdateFamily(Family family);

    /**
     * 修改头像
     */
    @Update("update family_users set avatar_url=#{avatarUrl} where id=#{familyId}")
    void updateAvatar(Integer familyId, String avatarUrl);

    /**
     * 删除家属用户
     */
    @Delete("delete from family_users where id=#{id}")
    void deleteById(Integer id);

    /**
     * 通过老人ID查询家属用户的phone
     */
    String getPhoneByOldManId(Integer oldManId);
}
